<?php

namespace Home\Controller;
use Think\Controller;

class RunController extends BaseController{

	public function ssc_kj(){
		$this->display();
	}

	public function bj28_kj(){
		$this->display();
	}


	public function bj28_fn(){
		$game = I('game');
		$this->assign('game',$game);
		$this->display();
	}

	public function jnd28_kj(){
		$this->display();
	}

	public function kefu_wx(){
		$info = M('config')->where("id =1")->find();
		$this->assign('info',$info);
		$this->display();
	}

	public function index(){

//        $var = 'wangya';
//
//        if(! $var ) $var = time().'b891037e3d772605f56f8e9877d8593c';
//        $varstr = strlen( $var );
//        if( $varstr < 1 ) $varstr = 32;
//        $hash = md5( ('#@$^%&^*&(#'.md5( base64_encode( $var.'.@#!$#@%#soft.com'.md5($var).'WangYa'. $var.'][{)(*&^%#@!~1d').'@monsof ~!~$^%&^*&(t'. $varstr). $varstr));
//
//        echo substr( $hash ,1 , $varstr * 3 );
//
//
//        exit;
		if(C('is_open')==0){
    		$this->redirect('error');
    	}
		$kefu = M('config')->where("id = 1")->find();
		$is_weixin = is_weixin();

		$auth = auth_check(C('auth_code'),$_SERVER['HTTP_HOST']);
		if (!$auth) {
			echo "Unauthorized or expired authorization";exit;
		}


		$adminconf=M('admin_config')->where('id=2')->field('peoplenumber,moneynumber')->find();
		//互动列表
		$article = M('hd');
		$count = $article->count();
		$page = new \Think\Page($count,5);
		$show = $page->show();
		$list = $article->limit($page->firstRow.','.$page->listRows)->order("addtime desc")->select();
		        $wheredata=array(
            'game'=>"Home page description settings",
            'status'=>1
        );

        // 公告
        $lang = cookie('userLanguage');
        $where = [];
        $where['status'] = 1;
        $where['lang'] = $lang=='' ? 'en' : $lang;
        $notices = M('notice')->where($where)->field('content')->select();
        $this->assign('notices',$notices);

        $neirong=M('gametest')->where($wheredata)->find();
        $this->assign('neirong',$neirong);
		
        $this->assign('data',$adminconf);

		$this->assign('show',$show);
		$this->assign('list',$list);
		$this->assign("auth",$auth);
		$this->assign('is_weixin',$is_weixin);
		$this->assign('kefu',$kefu);
		if (C('index_page') == '2') {
			$this->display("index_2");
		} else if(C('index_page') == '1') {
			$this->display("index_1");
		} else {
			$this->display('index_3');
		}
		
	}

	
	public function bj28(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}

		//10期结果
		$list = M('number')->where("game='bj28'")->order("id DESC")->limit(40)->select();
		
		// 创建SDK实例
		$script = &  load_wechat('Script');
		// 获取JsApi使用签名，通常这里只需要传 $ur l参数
		$url = 'http://'.$_SERVER['SERVER_NAME'].'/Home/Run/index.html';
		$options = $script->getJsSign($url, $timestamp, $noncestr, $appid);
		
		//判断赛车和飞艇的类型
		$kefu = M('config')->where("id = 1")->find();

		$is_weixin = is_weixin();

		$this->assign('is_weixin',$is_weixin);
		$this->assign('kefu',$kefu);

		$this->assign('list',$list);
		$this->assign('type',$type);
		$this->assign('options',$options);
		$this->display();
	}


	public function bj28_1(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}

	        // 10期结果
        $list = M('number')->where("game='bj28'")
            ->order("id DESC")
            ->limit(10)
            ->select();
        
        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);
        
        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();
        
        $is_weixin = is_weixin();
		
		
		$userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
		$order = M('order');
		$points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
		$this->assign('points_tj', $points_tj);
		
		
        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);
            
            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];
			
            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;
            
            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));
            
            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else 
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }
        
        $this->assign('kjlist', $kjlist);
		
		// 聊天信息
        $msglist = M('message')->where("status=1 and game='bj28_1'")
            ->order("id DESC")
            ->limit(50)
            ->select();

        $this->assign('msglist', $msglist);
		
        
        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);
        
        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '1') {
            $this->display("bj28_1");
        } else {
            $this->display();
        }
	}

	public function bj28_2(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}
        // 10期结果
        $list = M('number')->where("game='bj28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();


        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='bj28_2'")
            ->order("id DESC")
            ->limit(50)
            ->select();

        $this->assign('msglist', $msglist);


        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '2') {
            $this->display("bj28_2");
        } else {
            $this->display();
        }
	}

	public function bj28_3(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}
        // 10期结果
        $list = M('number')->where("game='bj28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();


        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='bj28_3'")
            ->order("id DESC")
            ->limit(50)
            ->select();

        $this->assign('msglist', $msglist);


        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '3') {
            $this->display("bj28_3");
        } else {
            $this->display();
        }
	}

	public function jnd28_1(){

		if(C('is_open')==0){
    		$this->redirect('error');
    	}

        // 10期结果
        $list = M('number')->where("game='jnd28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();

        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='jnd28_1'")
            ->order("id DESC")
            ->limit(50)
            ->select();
      
        $this->assign('msglist', $msglist);

        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '1') {
            $this->display("jnd28_1");
        } else {
            $this->display();
        }
	}

	public function jnd28_2(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}

        // 10期结果
        $list = M('number')->where("game='jnd28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();

        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='jnd28_2'")
            ->order("id DESC")
            ->limit(50)
            ->select();
        $this->assign('msglist', $msglist);

        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '2') {
            $this->display("jnd28_2");
        } else {
            $this->display();
        }
	}

	public function jnd28_3(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}

        // 10期结果
        $list = M('number')->where("game='jnd28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();

        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='jnd28_3'")
            ->order("id DESC")
            ->limit(50)
            ->select();
        $this->assign('msglist', $msglist);

        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '3') {
            $this->display("jnd28_3");
        } else {
            $this->display();
        }
	}
	
	public function jnd28_4(){
		if(C('is_open')==0){
    		$this->redirect('error');
    	}

        // 10期结果
        $list = M('number')->where("game='jnd28'")
            ->order("id DESC")
            ->limit(10)
            ->select();

        // 创建SDK实例
        $script = &  load_wechat('Script');
        // 获取JsApi使用签名，通常这里只需要传 $ur l参数
        $url = 'http://' . $_SERVER['SERVER_NAME'] . '/Home/Run/index.html';
        $options = $script->getJsSign($url, $timestamp, $noncestr, $appid);

        // 判断赛车和飞艇的类型
        $kefu = M('config')->where("id = 1")->find();

        $is_weixin = is_weixin();

        $userinfo = session('user');
        $map['state'] = 1;
        $map['userid'] = $userinfo['id'];
        $order = M('order');
        $points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")
            ->where($map)
            ->find();
        $points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
        $this->assign('points_tj', $points_tj);


        foreach ($list as $key => $value) {
            $current_number = $value;
            $number1 = explode(',', $current_number['awardnumbers']);

            $numberOne = $number1[0];
            $numberTwo = $number1[1];
            $numberThree = $number1[2];

            $tema_number = $numberOne + $numberTwo + $numberThree;
            $current_number[numberOne] = $numberOne;
            $current_number[numberTwo] = $numberTwo;
            $current_number[numberThree] = $numberThree;

            if ($tema_number <= 13) {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '小双';
                } else {
                    $current_number['zuhe'] = '小单';
                }
            } else {
                if ($tema_number % 2 == 0) {
                    $current_number['zuhe'] = '大双';
                } else {
                    $current_number['zuhe'] = '大单';
                }
            }
            if ($numberOne > $numberTwo) {
                $current_number['zx'] = '庄';
            } elseif ($numberOne == $numberTwo) {
                $current_number['zx'] = '和';
            } else {
                $current_number['zx'] = '闲';
            }
            $current_number['q3'] = bj28_qzh(array(
                $numberOne,
                $numberTwo,
                $numberThree
            ));

            if ($tema_number >= 0 && $tema_number <= 5) {
                $current_number['jdx'] = '极小';
            } else
                if ($tema_number >= 22 && $tema_number <= 27) {
                    $current_number['jdx'] = '极大';
                } else {
                    $current_number['jdx'] = '';
                }
            $kjlist[$key] = $current_number;
        }

        $this->assign('kjlist', $kjlist);

        // 聊天信息
        $msglist = M('message')->where("status=1 and game='jnd28_3'")
            ->order("id DESC")
            ->limit(50)
            ->select();
        $this->assign('msglist', $msglist);

        $this->assign('is_weixin', $is_weixin);
        $this->assign('kefu', $kefu);

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('options', $options);
        if (C('index_page') == '4') {
            $this->display("jnd28_4");
        } else {
            $this->display();
        }
	}
	
	

			/*竞猜*/
	public function jincaibj28_1(){
		//聊天信息
		$list = M('message')->where("status=1 and game='bj28_1'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaibj28_2(){
		//聊天信息
		$list = M('message')->where("status=1 and game='bj28_2'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaibj28_3(){
		//聊天信息
		$list = M('message')->where("status=1 and game='bj28_3'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaijnd28_1(){
		//聊天信息
		$list = M('message')->where("status=1 and game='jnd28_1'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaijnd28_2(){
		//聊天信息
		$list = M('message')->where("status=1 and game='jnd28_2'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaijnd28_3(){
		//聊天信息
		$list = M('message')->where("status=1 and game='jnd28_3'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}

	/*竞猜*/
	public function jincaijnd28_4(){
		//聊天信息
		$list = M('message')->where("status=1 and game='jnd28_4'")->order("id DESC")->limit(40)->select();
		$this->assign('list',$list);
		$this->display();
	}



		//开奖记录
	public function kjbj28(){
		//20期结果
		$list = M('number')->where("game='bj28'")->order("id DESC")->limit(40)->select();

		foreach ($list as $key => $value) {
			$current_number = $value;
			$number1 = explode(',', $current_number['awardnumbers']);
			$tema_number = $number1[0] + $number1[1] + $number1[2];
			if ($tema_number <= 13) {
				if ($tema_number%2 == 0) {
					$current_number['zuhe'] = '小双';
				} else {
					$current_number['zuhe'] = '小单';
				}
			} else {
				if ($tema_number%2 == 0) {
					$current_number['zuhe'] = '大双';
				} else {
					$current_number['zuhe'] = '大单';
				}
			}

			if ($tema_number >=0 && $tema_number <=5) {
				$current_number['jdx'] = '极小';
			} else if($tema_number >= 22 && $tema_number <=27) {
				$current_number['jdx'] = '极大';
			}  else {
				$current_number['jdx'] = '';
			}
			$list[$key] = $current_number;
		}

		$this->assign('list',$list);
		$this->display();
	}

	//开奖记录
	public function kjjnd28(){
		//20期结果
		$list = M('number')->where("game='jnd28'")->order("id DESC")->limit(40)->select();

		foreach ($list as $key => $value) {
			$current_number = $value;
			$number1 = explode(',', $current_number['awardnumbers']);
			$tema_number = $number1[0] + $number1[1] + $number1[2];
			if ($tema_number <= 13) {
				if ($tema_number%2 == 0) {
					$current_number['zuhe'] = '小双';
				} else {
					$current_number['zuhe'] = '小单';
				}
			} else {
				if ($tema_number%2 == 0) {
					$current_number['zuhe'] = '大双';
				} else {
					$current_number['zuhe'] = '大单';
				}
			}

			if ($tema_number >=0 && $tema_number <=5) {
				$current_number['jdx'] = '极小';
			} else if($tema_number >= 22 && $tema_number <=27) {
				$current_number['jdx'] = '极大';
			}  else {
				$current_number['jdx'] = '';
			}
			$list[$key] = $current_number;
		}

		$this->assign('list',$list);
		$this->display();
	}


	/*客服*/
	public function kefu(){
		$kefu = M('config')->where("id = 1")->find();
		$this->assign('kefu',$kefu);
		$this->display();
	}

	//推广二维码
	public function tui(){
		$uid = I('uid');
		$userinfo = M('user')->where("id={$uid}")->find();

		$this->assign('tui',$userinfo['qrcode']);
		$siteurl = $_SERVER['SERVER_NAME'];
		$url = 'http://'.$siteurl.'?t='.$uid;
		$this->assign('url',$url);
		$this->display();
	}

	public function app(){
		$this->display();
	}

	/*记录*/
	public function record(){
		$t = I('t');
		
		$map = array();
		if($t == 1){
			if (time() <= strtotime("06:00:00")) {
	    		$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
				$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
	    	}else{
	    		$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
				$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
	    	}
		}
		if($t == 2){
			$beginToday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
			$endToday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
		}
		if($t == 3){
			$beginToday=mktime(0,0,0,date('m'),date('d')-2,date('Y'));
			$endToday=mktime(0,0,0,date('m'),date('d')-1,date('Y'))-1;
		}
		if($t == 4){
			$beginToday=0;
			$endToday=0;
		}
		if ($beginToday and $endToday) {
			$map['time'] = array(array('egt',$beginToday),array('elt',$endToday),'and');
		}
		$userinfo = session('user');
		$map['state'] = 1;
		$map['userid'] = $userinfo['id'];
		
		$order = M('order');
		$count = $order->where($map)->count();
		$points_tj = $order->field("count(id) as count,sum(add_points) as sum_add,sum(del_points) as sum_del")->where($map)->find();
		$points_tj['ying'] = $points_tj['sum_add'] - $points_tj['sum_del'];
		$page = new \Think\Page($points_tj['count'],6);
		$show = $page->show();
		$list = $order->field("*")->where($map)->limit($page->firstRow.','.$page->listRows)->order("id DESC")->select();

		$number = array();
		for($i=0;$i<count($list);$i++){
			if(!in_array($list[$i]['number'], $number)){
				$number[] = $list[$i]['number'];
			}
			for($a=0;$a<count($number);$a++){
				if($list[$i]['number']==$number[$a]){
					$list1[$a]['number'] = $number[$a];
					$list1[$a]['game'] = $list[$i]['game'];
					$list1[$a]['order'][] = $list[$i];
				}
			}
		}
		
		
		$bj28_1data = F('bj28_1data');
		$bj28_2data = F('bj28_2data');
		$bj28_3data = F('bj28_3data');
		$jnd28_1data = F('jnd28_1data');
		$jnd28_2data = F('jnd28_2data');
		$jnd28_3data = F('jnd28_3data');
		$jnd28_4data = F('jnd28_4data');
		
		
		$this->assign('list1',$list1);
		$this->assign('state',F('state'));
		
		$this->assign('bj28_1number',$bj28_1data['next']['periodNumber']);
		$this->assign('bj28_2number',$bj28_2data['next']['periodNumber']);
		$this->assign('bj28_3number',$bj28_3data['next']['periodNumber']);
		$this->assign('jnd28_1number',$jnd28_1data['next']['periodNumber']);
		$this->assign('jnd28_2number',$jnd28_2data['next']['periodNumber']);
		$this->assign('jnd28_3number',$jnd28_3data['next']['periodNumber']);
		$this->assign('jnd28_4number',$jnd28_4data['next']['periodNumber']);
		
		$this->assign('list',$list);
		$this->assign('points_tj',$points_tj);
		$this->assign('show',$show);
		$this->assign('today',mktime(0,0,0,date('m'),date('d'),date('Y')));
		$this->assign('t',$t);
		$this->display();
	}
	
	/*规则*/
	public function rulebj28_1(){
		$config = M('config')->where("id=4")->find();
		$this->assign("config",$config);
		$this->display();
	}

	/*规则*/
	public function rulebj28_2(){
		$config = M('config')->where("id=5")->find();
		$this->assign("config",$config);
		$this->display();
	}

	/*规则*/
	public function rulebj28_3(){
		$config = M('config')->where("id=6")->find();
		$this->assign("config",$config);
		$this->display();
	}


	/*规则*/
	public function rulejnd28_1(){
		$config = M('config')->where("id=7")->find();
		$this->assign("config",$config);
		$this->display();
	}

	/*规则*/
	public function rulejnd28_2(){
		$config = M('config')->where("id=8")->find();
		$this->assign("config",$config);
		$this->display();
	}

	/*规则*/
	public function rulejnd28_3(){
		$config = M('config')->where("id=9")->find();
		$this->assign("config",$config);
		$this->display();
	}
	
	/*规则*/
	public function rulejnd28_4(){
		$config = M('config')->where("id=9")->find();
		$this->assign("config",$config);
		$this->display();
	}

	/*查询分数*/
	public function check_points(){
		if(IS_POST){
			if(IS_AJAX){
				$id = I('id');
				if($id){
					$userinfo = M('user')->where("id = $id")->find();
					if($userinfo){
						$userinfo['error']=0;
					}
				}
				$this->ajaxReturn($userinfo);
			}
		}
	}
	
	public function del(){
		$id = I('id');
		$info = M('order')->where("id = $id")->find();
		if(!$info){
			$data['error']==0;
			$data['msg']=='未找到订单';
		} else {
			$state = F($info['game'] . '_state');
			$pkdata = F($info['game'] . 'data');
			if($state==1){
				$id = I('id');
				if($info['number']==$pkdata['next']['periodNumber']){
					$res = M('order')->where("id = $id")->setField('state',0);
					if($res){
						$data['error']==1;
						//加分
						M('user')->where("id = {$info['userid']}")->setInc('points',$info['del_points']);
						//记录日志
						$userlog = array(
						'username' => $info['username'],
						'nickname' => $info['nickname'],
						'type' => 6, //1 下注  2中奖 3上分  4下分  5登录系统   6取消下注
						'addtime' => time(),
						'content' => "用户取消订单，期号[".$info['number']."],取消金额[".$info['del_points']."],取消下注内容[".$info['jincai']."]",
					);
					M('userlog')->add($userlog);
					}else{
						$data['error']==0;
						$data['msg']=='删除失败';
					}
				}else{
					$data['error']==0;
					$data['msg']=='本期已封盘';
				}
			}else{
				$data['error']==0;
				$data['msg']=='本期已封盘';
			}
		}
		$this->ajaxReturn($data);

	
		
	}

	public function hd(){
		$id = I('id');
		$info = M('hd')->where("id = {$id}")->find();
		$this->assign("info",$info);
		$this->display();
	}
	

	public function kaijiang(){
		$type = I('type');
		//20期结果
		$list = M('number')->where("game='{$type}'")->order("id DESC")->limit(40)->select();

		$this->assign("list",$list);
		$this->display();
	}
	
	
}



?>